﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using IYAKASAPortal.Services;
using BLL;
using Model;
using DBUtility;

namespace IYAKASAPortal
{
    public partial class Frame_Left : System.Web.UI.Page
    {

        public string g_strTreeJS = "";
        private UserInfo userInfo { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            //g_strTreeJS = "d.add(0,-1,'弥荣登录系统');";

            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
            {
                string userName = Session["UserName"].ToString();
                userInfo = IYAKASAPortal.Services.UserAuthority.GetUserAuthority(userName);
            }

            string userRole= userInfo.UserRole;
            string[] roles = userRole.Split(',');
            string result="";
            string rights = ",";
            for (int i = 0; i < roles.Length; i++)
            {
                if (!string.IsNullOrEmpty(roles[i]))
                {
                    result+= DbHelper.GetValue("select rights from SYSTEM_ROLE_RIGHT where role='" + roles[i] + "'");
                }
            }
            string[] rightsArr = result.Split(',');
            for (int i = 0; i < rightsArr.Length; i++)
            {
                if (!string.IsNullOrEmpty(rightsArr[i]))
                {
                    if (rights.IndexOf(","+rightsArr[i]+",") < 0)
                    {
                        rights += rightsArr[i] + ",";
                    }
                }
            }

            string[] rightsSrot = rights.Substring(1,rights.Length-2).Split(',');
            Array.Sort(rightsSrot);
            string newRights=",";
            for (int i = 0; i < rightsSrot.Length; i++)
            {
                newRights += rightsSrot[i] + ",";
            }

            SYSTEM_MODULE_BLL m_Moudle_BLL = new SYSTEM_MODULE_BLL();
            SYSTEM_MODULE m_Moudle = new SYSTEM_MODULE();
            int id = 0;

            string[] rightsList = newRights.Split(',');
            for (int i = 0; i < rightsList.Length; i++)
            {
                if (!string.IsNullOrEmpty(rightsList[i]))
                {
                    id = int.Parse(rightsList[i]);
                    m_Moudle=m_Moudle_BLL.GetModel(id);
                    if (string.IsNullOrEmpty(m_Moudle.murl))
                    {
                        g_strTreeJS += "d.add(" + m_Moudle.mid + "," + m_Moudle.pid + ",'" + m_Moudle.mname + "','');";
                    }
                    else
                    {
                        g_strTreeJS += "d.add(" + m_Moudle.mid + "," + m_Moudle.pid + ",'" + m_Moudle.mname + "','" + m_Moudle.murl + "?random=" + new Random().NextDouble().ToString() + "');";
                    }
                    
                }

            }

            #region 登陆权限[旧]
            //    //厂家权限
            //    if (userInfo.UserPower == "0")
            //    {
            //        g_strTreeJS += "d.add(100,0,'登录','');";
            //        g_strTreeJS += "d.add(200,0,'调度','');";
            //        g_strTreeJS += "d.add(300,0,'打印','');";
            //        g_strTreeJS += "d.add(400,0,'管理','');";
            //        g_strTreeJS += "d.add(500,0,'设备管理','');";
            //        g_strTreeJS += "d.add(1001,100,'安检登录','Login/LoginAJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1002,100,'综检登录','Login/LoginZJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1003,100,'排放登录','Login/LoginPQ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1004,100,'登录列表','Login/LoginSelect.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(3001,300,'打印设置','PrintAll/PrintConfig.aspx');";
            //        g_strTreeJS += "d.add(3002,300,'打印安检','PrintAll/PrintAJList.aspx');";
            //        g_strTreeJS += "d.add(3003,300,'打印综检','PrintAll/PrintZJList.aspx');";
            //        g_strTreeJS += "d.add(3004,300,'打印排放','PrintAll/PrintHBSYList.aspx');";
            //        g_strTreeJS += "d.add(3005,300,'自动打印','PrintAll/PrintAuto.aspx');";
            //        g_strTreeJS += "d.add(3006,300,'打印牌证','PrintAll/PrintJDCPZList.aspx');";
            //        g_strTreeJS += "d.add(4002,400,'成员管理','Admin.aspx');";
            //        g_strTreeJS += "d.add(2001,200,'车辆底盘审查','LabourVerify/LabourVerify.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //    }
            //    //监督部门
            //    else if (userInfo.UserPower == "1")
            //    {

            //    }
            //    //站长+管理员
            //    else if (userInfo.UserPower == "2" || userInfo.UserPower == "3")
            //    {
            //        g_strTreeJS += "d.add(100,0,'登录','');";
            //        g_strTreeJS += "d.add(200,0,'调度','');";
            //        g_strTreeJS += "d.add(300,0,'打印','');";
            //        g_strTreeJS += "d.add(400,0,'管理','');";
            //        g_strTreeJS += "d.add(1001,100,'安检登录','Login/LoginAJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1002,100,'综检登录','Login/LoginZJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1003,100,'排放登录','Login/LoginPQ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1004,100,'登录列表','Login/LoginSelect.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(3001,300,'打印设置','PrintAll/PrintConfig.aspx');";
            //        g_strTreeJS += "d.add(3002,300,'打印安检','PrintAll/PrintAJList.aspx');";
            //        g_strTreeJS += "d.add(3003,300,'打印综检','PrintAll/PrintZJList.aspx');";
            //        g_strTreeJS += "d.add(3004,300,'打印排放','PrintAll/PrintHBSYList.aspx');";
            //        g_strTreeJS += "d.add(3005,300,'自动打印','PrintAll/PrintAuto.aspx');";
            //        g_strTreeJS += "d.add(3006,300,'打印牌证','PrintAll/PrintJDCPZList.aspx');";
            //        g_strTreeJS += "d.add(4002,400,'成员管理','Admin.aspx');";
            //        g_strTreeJS += "d.add(2001,200,'车辆底盘审查','LabourVerify/LabourVerify.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //    }
            //    //设备级管理员
            //    else if (userInfo.UserPower == "4")
            //    {

            //    }

            //    ///普通操作员
            //    else if (userInfo.UserPower == "5")
            //    {
            //        g_strTreeJS += "d.add(100,0,'收费管理','');";
            //        g_strTreeJS += "d.add(200,0,'登录管理','');";
            //        g_strTreeJS += "d.add(300,0,'报告单查看','');";
            //        g_strTreeJS += "d.add(350,0,'调度查看','');";
            //        g_strTreeJS += "d.add(400,0,'系统管理','');";
            //        g_strTreeJS += "d.add(500,0,'统计管理','');";
            //        g_strTreeJS += "d.add(600,0,'系统设置','');";

            //        g_strTreeJS += "d.add(1010,100,'收费','Charge/ChargeSF.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1020,100,'退费','Charge/ChargeTF.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1030,100,'统计','Charge/ChargeTJ.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(2001,200,'安检','Login/LoginAJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(2002,200,'综检','Login/LoginZJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(2003,200,'排放','Login/LoginPQ.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(3002,300,'安检','PrintAll/PrintAJList.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(3003,300,'综检','PrintAll/PrintZJList.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(3004,300,'排放','PrintAll/PrintHBSYList.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(3501,350,'调度查看','LabourVerify/VehicleDD.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(4100,400,'设备管理','');";
            //        g_strTreeJS += "d.add(4110,4100,'设备管理','InsManage/DEV_INFO_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(4210,400,'标准管理','');";
            //        g_strTreeJS += "d.add(4310,400,'人员管理','');";
            //        g_strTreeJS += "d.add(4410,400,'车型库管理','');";

            //        g_strTreeJS += "d.add(42101,4210,'速度标准','Standard/DEV_STANDARD_SPEED_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42102,4210,'侧滑标准','Standard/DEV_STANDARD_SIDESLIP_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42103,4210,'制动标准','Standard/DEV_STANDARD_BRAKE_ZJ_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42104,4210,'灯光标准','Standard/DEV_STANDARD_LAMP_ZJ_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42105,4210,'双怠速标准','Standard/DEV_STANDARD_SDS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42106,4210,'自由加速标准','Standard/DEV_STANDARD_ZYJS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42107,4210,'VMAS标准','Standard/DEV_STANDARD_VMAS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42108,4210,'ASM标准','Standard/DEV_STANDARD_ASM_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42109,4210,'加载减速准','Standard/DEV_STANDARD_LD_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42110,4210,'底盘测功标准','Standard/DEV_STANDARD_DPCG_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42111,4210,'噪音标准','Standard/DEV_STANDARD_NOSIZE_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42112,4210,'出租车里程标准','Standard/DEV_STANDARD_TAXI_MILEAGE_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42113,4210,'声级标准','Standard/DEV_STANDARD_SPEAKER_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42114,4210,'悬架标准','Standard/DEV_STANDARD_SUSPENSION_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42115,4210,'整备质量标准','Standard/DEV_STANDARD_KERBMASS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(4311,4310,'人员管理','Admin.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(44101,4410,'品牌型号','Standard/TYPE_CX_CONTENT_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(44102,4410,'发动机类型','Standard/TYPE_CX_FDJ_UNION_List.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(5010,500,'安检','');";
            //        g_strTreeJS += "d.add(50101,5010,'车辆种类','Statistics/PrintCLZL.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(50102,5010,'检测类别','Statistics/PrintCLZL.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(5020,500,'综检','');";
            //        g_strTreeJS += "d.add(50201,5020,'车辆种类','');";
            //        g_strTreeJS += "d.add(50202,5020,'检测类别','');";

            //        g_strTreeJS += "d.add(6010,600,'打印','');";
            //        g_strTreeJS += "d.add(60101,6010,'打印设置','PrintAll/PrintConfig.aspx');";
            //        g_strTreeJS += "d.add(60102,6010,'自动打印','PrintAll/PrintAuto.aspx');";
            //        g_strTreeJS += "d.add(60103,6010,'打印牌证','PrintAll/PrintJDCPZList.aspx');";
            //        g_strTreeJS += "d.add(6020,600,'常量','');";
            //        g_strTreeJS += "d.add(60201,6020,'常量定义','Standard/CONST_DEFINE_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(60202,6020,'类别','Standard/CONST_DEFINE_WEB_CATEGORY_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(60203,6020,'类别详细','Standard/CONST_DEFINE_WEB_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //    }
            //    //无权限
            //    else if (string.IsNullOrEmpty(userInfo.UserPower))
            //    {
            //        g_strTreeJS += "d.add(100,0,'收费管理','');";
            //        g_strTreeJS += "d.add(200,0,'登录管理','');";
            //        g_strTreeJS += "d.add(300,0,'报告单查看','');";
            //        g_strTreeJS += "d.add(350,0,'调度查看','');";
            //        g_strTreeJS += "d.add(400,0,'系统管理','');";
            //        g_strTreeJS += "d.add(500,0,'统计管理','');";
            //        g_strTreeJS += "d.add(600,0,'系统设置','');";

            //        g_strTreeJS += "d.add(1010,100,'收费','Charge/ChargeSF.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1020,100,'退费','Charge/ChargeTF.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(1030,100,'统计','Charge/ChargeTJ.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(2001,200,'安检','Login/LoginAJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(2002,200,'综检','Login/LoginZJ.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(2003,200,'排放','Login/LoginPQ.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(3002,300,'安检','PrintAll/PrintAJList.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(3003,300,'综检','PrintAll/PrintZJList.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(3004,300,'排放','PrintAll/PrintHBSYList.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(3501,350,'调度查看','LabourVerify/VehicleDD.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(4100,400,'设备管理','');";
            //        g_strTreeJS += "d.add(4110,4100,'设备管理','InsManage/DEV_INFO_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(4210,400,'标准管理','');";
            //        g_strTreeJS += "d.add(4310,400,'人员管理','');";
            //        g_strTreeJS += "d.add(4410,400,'车型库管理','');";

            //        g_strTreeJS += "d.add(42101,4210,'速度标准','Standard/DEV_STANDARD_SPEED_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42102,4210,'侧滑标准','Standard/DEV_STANDARD_SIDESLIP_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42103,4210,'制动标准','Standard/DEV_STANDARD_BRAKE_ZJ_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42104,4210,'灯光标准','Standard/DEV_STANDARD_LAMP_ZJ_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42105,4210,'双怠速标准','Standard/DEV_STANDARD_SDS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42106,4210,'自由加速标准','Standard/DEV_STANDARD_ZYJS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42107,4210,'VMAS标准','Standard/DEV_STANDARD_VMAS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42108,4210,'ASM标准','Standard/DEV_STANDARD_ASM_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42109,4210,'加载减速准','Standard/DEV_STANDARD_LD_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42110,4210,'底盘测功标准','Standard/DEV_STANDARD_DPCG_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42111,4210,'噪音标准','Standard/DEV_STANDARD_NOSIZE_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42112,4210,'出租车里程标准','Standard/DEV_STANDARD_TAXI_MILEAGE_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42113,4210,'声级标准','Standard/DEV_STANDARD_SPEAKER_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42114,4210,'悬架标准','Standard/DEV_STANDARD_SUSPENSION_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(42115,4210,'整备质量标准','Standard/DEV_STANDARD_KERBMASS_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(4311,4310,'人员管理','Admin.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(44101,4410,'品牌型号','Standard/TYPE_CX_CONTENT_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(44102,4410,'发动机类型','Standard/TYPE_CX_FDJ_UNION_List.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(5010,500,'安检','');";
            //        g_strTreeJS += "d.add(50101,5010,'车辆种类','Statistics/PrintCLZL.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(50102,5010,'检测类别','Statistics/PrintCLZL.aspx?random=" + new Random().NextDouble().ToString() + "');";

            //        g_strTreeJS += "d.add(5020,500,'综检','');";
            //        g_strTreeJS += "d.add(50201,5020,'车辆种类','');";
            //        g_strTreeJS += "d.add(50202,5020,'检测类别','');";

            //        g_strTreeJS += "d.add(6010,600,'打印','');";
            //        g_strTreeJS += "d.add(60101,6010,'打印设置','PrintAll/PrintConfig.aspx');";
            //        g_strTreeJS += "d.add(60102,6010,'自动打印','PrintAll/PrintAuto.aspx');";
            //        g_strTreeJS += "d.add(60103,6010,'打印牌证','PrintAll/PrintJDCPZList.aspx');";
            //        g_strTreeJS += "d.add(6020,600,'常量','');";
            //        g_strTreeJS += "d.add(60201,6020,'常量定义','Standard/CONST_DEFINE_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(60202,6020,'类别','Standard/CONST_DEFINE_WEB_CATEGORY_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //        g_strTreeJS += "d.add(60203,6020,'类别详细','Standard/CONST_DEFINE_WEB_List.aspx?random=" + new Random().NextDouble().ToString() + "');";
            //    }
            //}
            #endregion
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="conn">连接符</param>
        /// <param name="user">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="popedom">权限</param>
        /// <param name="errmsg">登录错误消息</param>
        /// <returns>返回登录是否成功</returns>
        public static bool Login(string conn, string user, string password, out uint popedom, out string errmsg)
        {
            errmsg = "";
            popedom = 0;
            return false;
        }
    }
}
